﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using jsm.SqlHelper;

namespace dbcaac
{
    public sealed class EntityJiyuanNRSHSub : EntityBase
    {
        public string jyrzChangedId { get; private set; }

        public override void loadPageData(HttpContext context)
        {
            jyrzChangedId = context.Request["s_id"];
        }

        public override int getTotal()
        {
            string sql = string.Format("SELECT count(*) FROM [jiyuanNRLog] WHERE (jyrzChangedId = {0}) AND (jyrzApprovalStatus = 'UNAPPROVED')", jyrzChangedId);
            return (int)SqlServerHelper.ExecuteScalar(sql);
        }

        protected override int doInsertOperation()
        {
            throw new NotImplementedException();
        }

        protected override int doDeleteOperation()
        {
            throw new NotImplementedException();
        }

        protected override int doUpdateOperation()
        {
            throw new NotImplementedException();
        }

        public override SqlDataReader executeDataReader()
        {
            string sqlText = null;
            List<SqlParameter> sqlParams = new List<SqlParameter>();

            sqlText = @"SELECT jyrzLogId AS xgLogId, jyrzChangedId AS xgId, 
                        (SELECT nbyhName from [neibuYH] WHERE nbyhId = aTbl.jyrzChangedBy) AS xgPerson, 
                        (CASE WHEN jyrzChangedType='DELETE' THEN '删除' WHEN jyrzChangedType='NEW' THEN '新增' 
                        WHEN jyrzChangedType='UPDATE' THEN '修改' END) AS xgType, CONVERT(VARCHAR(100), jyrzChangedDate, 120) AS xgDate
                        FROM [jiyuanNRLog] AS aTbl WHERE (jyrzChangedId = @jyrzChangedId) AND (jyrzApprovalStatus = 'UNAPPROVED')";
            sqlParams.Add(new SqlParameter("@jyrzChangedId", jyrzChangedId));

            return SqlServerHelper.ExecuteReader(sqlText, sqlParams.ToArray());
        }
    }
}
